package com.smilive.start.netty.netty;

import java.util.concurrent.*;

/**
 * @program: netty
 * @Date: 2022-01-05 15:00
 * @Author: smilive
 * @Description:
 */
public class JdkFuture {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadFactory factory = new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                return new Thread(r, "JdkFuture");
            }
        };
        // 创建线程池
        ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 2,10, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10), factory);

        Future<String> future = executor.submit(new Callable<String>() {

            @Override
            public String call() throws Exception {
                TimeUnit.SECONDS.sleep(1);
                return "smilive";
            }
        });

        //通过阻塞方式获取运行结果
        System.out.println(future.get());
    }
}
